
<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-lx-calendar"></i> 表单</el-breadcrumb-item>
                <el-breadcrumb-item>编辑器</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <quill-editor ref="myTextEditor" v-model="content" :options="editorOption"></quill-editor>
            <el-button class="editor-btn" type="primary" @click="submit">提交投诉</el-button>
        </div>
    </div>
</template>

<script>
    import 'quill/dist/quill.core.css';
    import 'quill/dist/quill.snow.css';
    import 'quill/dist/quill.bubble.css';
    import {quillEditor} from 'vue-quill-editor';

    export default {
        name: 'editor',
        data: function () {
            return {
                id: '-1',
                content: '',
                editorOption: {
                    placeholder: 'Hello World'
                }
            }
        },
        components: {
            quillEditor
        },
        methods: {
            onEditorChange({editor, html, text}) {
                this.content = text;
            },
            submit() {
                this.onEditorChange
                console.log(this.content);
                if (this.content != null) {
                    const _this = this
                    this.$axios.get('http://localhost:8888/complain/add',{
                        params: {
                            id: this.id,
                            content: this.content
                        }
                    }).then(res => {
                        console.log(res)
                        _this.$alert('操作成功', '提示', {
                            confirmButtonText: '确定',
                            callback: action => {
                                _this.$router.push("/tableComplain")
                                //这个/table路径要在router中的index中配置
                            }
                        });

                    })

                } else {
                    console.log('error submit!!');
                    alert("不能为空")
                    return false;
                }
            },
            getInfo() {
                console.log(this.$route.query.num.complainContent+"------------------")

                    this.id = this.$route.query.num.id;
                    this.content = this.$route.query.num.complainContent;

            }
        },
        watch:{
          '$route'(to,from){
              if (this.$route.query.num != undefined) {
                  this.getInfo();
              }
          }
        },
        created() {
            /*两种操作用一个页面解决笨方法1：
            * 判断有参数传过来的那个是不是undefined
            * 是就代表add
            * 否就代表edit*/
            console.log(this.$route.query.num)

            if (this.$route.query.num != undefined) {
                this.getInfo();
            }
        }
    }
</script>
<style scoped>
    .editor-btn {
        margin-top: 20px;
    }
</style>
